import 'package:flutter/material.dart';

///zhudaihao
///2024-1-30
///自定义AppBar
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  ///标题文本
  final String? title;

  ///自定义标题文本图标
  final Widget? titleWidget;

  ///自定义右边图标
  final Widget? leading;

  ///点击返回键回调
  final Function? onClickBack;

  const CustomAppBar(
      {this.title, this.titleWidget, this.leading, this.onClickBack, Key? key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: const Color(0xFF0B0B0F),
      padding: const EdgeInsets.only(top: 32),
      child: SizedBox(
        height: 56,
        child: Row(
          children: [
            titleWidget ??
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    InkWell(
                      child: const Padding(
                          padding: EdgeInsets.only(left: 16, right: 4, top: 2),
                          child: Icon(
                            Icons.arrow_back_ios_new_outlined,
                            size: 20,
                            color: Colors.white,
                          )),
                      onTap: () {
                        Navigator.pop(context);
                      },
                    ),
                    Text(
                      title ?? '',
                      style: const TextStyle(color: Colors.white, fontSize: 20),
                      textAlign: TextAlign.center,
                    )
                  ],
                ),
            const Spacer(),
            leading ?? const SizedBox(width: 0, height: 0),
          ],
        ),
      ),
    );
  }

  @override

  /// 设置appBar 宽高
  Size get preferredSize => const Size(double.infinity, 88);
}
